////////////////////////////////////////////////////////////////////////////////
//
//  MICROSOFT CORPORATION
//  Copyright (c) Microsoft Corporation.
//  All Rights Reserved.
//
//  NOTICE: Microsoft Confidential. Intended for Internal Use Only.
//
////////////////////////////////////////////////////////////////////////////////

import flash.events.Event;
import flash.events.EventDispatcher
import flash.events.IEventDispatcher;

//--------------------------------------------------------------------------
//
//  Properties
//
//--------------------------------------------------------------------------

/**
 * @private
 */
private var _dispatcher:IEventDispatcher = null;

/**
 * Returns the composited IEventDispatcher instance.
 */
protected function get dispatcher():IEventDispatcher
{
    return _dispatcher || (_dispatcher = createDispatcher());
}

//--------------------------------------------------------------------------
//
//  Methods
//
//--------------------------------------------------------------------------

/**
 * Registers an event listener object with an EventDispatcher object so that
 * the listener receives notification of an event.
 *
 * @see flash.events.IEventDispatcher#addEventListener
 */
public function addEventListener(type:String, listener:Function,
                                 useCapture:Boolean = false, priority:int = 0,
                                 useWeakReference:Boolean = false):void
{
    this.dispatcher.addEventListener(type, listener, useCapture, priority,
                                     useWeakReference);
}

/**
 * Removes a listener from the EventDispatcher object.
 *
 * @see flash.events.IEventDispatcher#removeEventListener
 */
public function removeEventListener(type:String, listener:Function,
                                    useCapture:Boolean = false):void
{
    this.dispatcher.removeEventListener(type, listener, useCapture);
}

/**
 * Dispatches an event into the event flow.
 *
 * @see flash.events.IEventDispatcher#dispatchEvent
 */
public function dispatchEvent(event:Event):Boolean
{
    return this.dispatcher.dispatchEvent(event);
}

/**
 * Checks whether the EventDispatcher object has any listeners registered
 * for a specific type of event.
 *
 * @see flash.events.IEventDispatcher#hasEventListener
 */
public function hasEventListener(type:String):Boolean
{
    return this.dispatcher.hasEventListener(type);
}

/**
 * Checks whether an event listener is registered with this EventDispatcher
 * object or any of its ancestors for the specified event type.
 *
 * @see flash.events.IEventDispatcher#willTrigger
 */
public function willTrigger(type:String):Boolean
{
    return this.dispatcher.willTrigger(type);
}

/**
 * Create new EventDispatcher; override this method for endo-testing, etc.
 */
protected function createDispatcher():IEventDispatcher
{
    return new EventDispatcher(this);
}
